var nowing='1';//1可以执行  2 执行中
var page=1;//定位当前页数
var index = 1;
var forEnd =0;
var showPage=10;//初始化最多显示的页数
var showPageCount=10;//初始化每页显示的条数
var parent=34;
initMenu();//初始化二级菜单
var ouid="0";
var ckType = getQueryString('type');
var menu = getQueryString('menu');
var mc="0";
loadDataSGS(ckType,1,10,1,ouid,mc);

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}


//初始化二级菜单
function initMenu(){
	$.ajax({
		  type: "post",
		  url: "../menu/querySecondMenuQian",
		  data: {
			  'parentId':parent
			  },
		  dataType: "json",
		  success: function(data){
			  var parentMenu = data.parentMenu;//父级菜单
			  var menuList = data.menuList;//二级菜单集合
			  $("#modulename").html(parentMenu.text);
			  $("#titleId").html(parentMenu.text);
			  $("#textbluebId").html(parentMenu.text);
			  
			  var menuStr ='';
			   $.each(menuList, function(index, entity){ 
				   var houUrl=entity.houUrl;
				   var shuzu =[];
				   shuzu = houUrl.split('ckType=');
				   var cktype = '';
				   if(shuzu.length>=2){
					   cktype=shuzu[1];
					   var shuzu2 = [];
					   shuzu2 = cktype.split('&');
					   if(shuzu2.length>=1){
						   cktype=shuzu2[0];
					   }
				   }
				   if(cktype!=''&&cktype!=100){
					   
					   menuStr+='<a href="page_list.html?parent=34&menu='+entity.id+'"><li id="id'+cktype+'" class='
						   +(entity.id==menu?"presentnav":"")
						   +'>'
						   +entity.text
						   +'</li></a>'; 
				   }else {
					   
					   if(entity.id=='69'||entity.id==69){
						   cktype=1;//行政许可
					   }else if(entity.id=='70'||entity.id==70){
						   cktype=2;//行政处罚
					   }
					   
					   menuStr+='<a href="javascript:loadDataSGS('+cktype+',1,'+showPageCount+',1,'+ouid+','+mc+');"><li id="id'+cktype+'"class='
					   +(entity.id==menu?"presentnav":"")
					   +'>'
					   +entity.text
					   +'</li></a>';
				   }
				  
				   
			    })
			    $("#pagenavId").append(menuStr); 
		  }
	  }) 
}

//点击双公示二级菜单时触发
function loadDataSGS(ckType,page,showPageCount,isInit,ouid,mc){
	nowing='2';
	if(isInit==1){
		page=1;//定位当前页数
		index = 1;	
		forEnd =0;
	}
	$("#listtable").empty();
	$("#depatmentlist").empty();
	$("#pagnub").empty();
	$("#sou").empty();
	$("#pagenavId li").removeClass("presentnav");
	$("#id"+ckType).attr("class","presentnav");
	$.ajax({
			  type: "post",
			  url: "../many/querySgs",
			  data: {
				  'ckType':ckType,
				  'page':page,
				  'count':showPageCount,
				  'ouid':ouid,
				  'mc':encodeURI(encodeURI(mc))
				  },
			  dataType: "json",
			  error:function(){
				  nowing='1';
			  },
			  success: function(data){
				  var rows = data.list;//集合
				  var total=data.total;//总条数
				  var bm=data.listbm;//部门
				  var rowsStr='';
				  var bmStr='';
				  
				  //获取部门数据
				  $.each(bm, function(index, entity){
					  var uid="'"+entity.ouid+"'";
					  bmStr+='<li><a href="javascript:loadDataSGS('+ckType+','+page+','+showPageCount+',1,'+uid+',0);">'+entity.ouname+'</a></li>';
				  });
				  
				  $("#depatmentlist").append(bmStr);
				  //获取列表数据
				  $.each(rows, function(index, entity){
					  var nowDate = entity.sjc;
					  var now = new Date(nowDate);
					  var time= now.format("yyyy-MM-dd");
					  var xzjg=entity.xzjg.replace(/\s/g, "");
					  if(ckType=='1'||ckType==1){
						  rowsStr+='<li class="credit-info-cont"><dl><dd class="object-type1">'
							+'<a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank"> '+entity.xdr+'</a> </dd>'
		                    +'<dd class="object-type2">  <a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'+xzjg+' </a> </dd>'
		                    +'<dd class="object-type3"> <a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'+entity.mc+' </a> </dd>'
		                    +'<dd style="width:15%;">'+time+'</dd></dl></li>';
					  }else if(ckType=='2'||ckType==2){
						  rowsStr+='<li class="credit-info-cont"><dl><dd class="object-type1">'
								+'<a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank"> '+entity.xdrmc+'</a> </dd>'
			                    +'<dd class="object-type2">  <a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'+xzjg+' </a>  </dd>'
			                    +'<dd class="object-type3"> <a href="page_publicity_table.html?parent=34&id='+entity.id+'&type='+ckType+'" target="_blank">'+entity.mc+' </a>  </dd>'
			                    +'<dd style="width:15%;">'+time+' </dd></dl></li>';
					  }
					  
				  });   
				  $("#listtable").append(rowsStr);
				  var pageAll =data.pageCount ;//总页数
				  
				  if(page==1){
					  forEnd = pageAll;
					  if(forEnd>=showPage){
						  forEnd=showPage;
					  }else {
						  forEnd = pageAll;
					  }
				  }
				  
				  ouid="'"+ouid+"'";
				  mc="'"+mc+"'";
				  var totalStr1='<a href="javascript:loadBegin('+ckType+','+ouid+','+mc+');">'
				  	  +'<span class="top"></span></a>'
				      +'<a href="javascript:loadUp('+ckType+','+page+','+ouid+','+mc+');">'
				      +'<span class="arrowleft"></span></a>';
				  var totalStr2='';
				 
				  
				  for (var i = index; i <=forEnd; i++) {
					
					if(page==i){
						totalStr2+='<a  id="aid'+i+'"' 
						+'href="javascript:loadIndex('+ckType+','+i+','+ouid+','+mc+');"><b>'+i+'</b></a>';
					}else{
						totalStr2+='<a id="aid'+i+'"' 
						+'href="javascript:loadIndex('+ckType+','+i+','+ouid+','+mc+');"><span>'+i+'</span></a>';
					}
				  }
				  if(forEnd<pageAll){
					  totalStr2+=' ......';
				  }
				 var totalStr = totalStr1+totalStr2;
				  totalStr+='<a href="javascript:loadNext('+ckType+','+page+','+pageAll+','+ouid+','+mc+');">'
				      +'<span class="arrowrightactive"></span></a>'
				      +'<a href="javascript:loadEnd('+ckType+','+pageAll+','+ouid+','+mc+');">'
				      +'<span class="bottomactive"></span></a>';
				  $("#pagnub").append(totalStr);
					nowing='1';
				var sou='<input name="sou" type="button" class="butsearc" value="结果中搜索" onclick="loadDataSS('+ckType+');"/>';
				 $("#sou").append(sou);
			  }
		 })
		 
}



//下一页
function loadNext(ckType,page,pageAll,ouid,mc){
	if(nowing=='2'){
		//alert("正在查询...");
		return;
	}
	if(page>=pageAll){
		page=pageAll;
		return;
	}
	
	if(page%showPage==0){
		  forEnd=page+showPage;
		  if(forEnd>=pageAll){
			  forEnd=pageAll;
		  }
		  index =page+1;   
	 }
	page=page+1;
	
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
	 
	
}
//最后一页
function loadEnd(ckType,pageAll,ouid,mc){
	
	if(nowing=='2'){
		//alert("正在查询...");
		return;
	}
	if(pageAll==0){
		return;
	}
	if(page==pageAll){
		return;
	}
	page=pageAll;
	forEnd=page;
	if(page%showPage!=0){
		index =page-(page%showPage)+1;
	}else{
		index =page-(showPage-1);
	}
	if(index<=1){
		index=1;
	}
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
	 
}
//上一页
function loadUp(ckType,page,ouid,mc){
	if(nowing=='2'){
		//alert("正在查询...");
		return;
	}
	if(page<=1){
		page=1;
		return;
	}
	if((page-1)%showPage==0){
		  index =page-showPage; 
		  forEnd=page-1;
	 }
	page=page-1;
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
	
}
//首页
function loadBegin(ckType,ouid,mc){
	if(nowing=='2'){
		//alert("正在查询...");
		return;
	}
	page=1;
	forEnd=showPage;
	index =1; 
	
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
	 
}
//点击数字跳转到具体的页数
function loadIndex(ckType,p,ouid,mc){
	if(nowing=='2'){
		//alert("正在查询...");
		return;
	}
	page=p;
	 
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
	 
}
//按结果 
function loadDataSS(ckType){
	page=1;
	forEnd=showPage;
	mc=$("#mc").val();
	if(mc==null||mc==''){
		mc='0';
	}
	loadDataSGS(ckType,page,showPageCount,0,ouid,mc);
}


Date.prototype.format = function(format){
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(), //day
	"h+" : this.getHours(), //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3), //quarter
	"S" : this.getMilliseconds() //millisecond
	}

	if(/(y+)/.test(format)) {
	format = format.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	}

	for(var k in o) {
	if(new RegExp("("+ k +")").test(format)) {
	format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
	}
	}
	return format;
	} 